import SwiftUI

enum ShadowType {
    case g_shadow_small
    case g_shadow_samll_upwards
    case g_shadow_medium
    case g_shadow_large
}

struct ShadowViewModifier: ViewModifier {
    var type: ShadowType

    func body(content: Content) -> some View {
        content
            .shadow(color: shadowColor,
                    radius: shadowRadius,
                    x: shadowX,
                    y: shadowY)
    }

    private var shadowColor: Color {
        switch type {
        case .g_shadow_small:
            return Color.g_color_shadow.opacity(0.16)
        case .g_shadow_samll_upwards:
            return Color.g_color_shadow.opacity(0.16)
        case .g_shadow_medium:
            return Color.g_color_shadow.opacity(0.16)
        case .g_shadow_large:
            return Color.g_color_shadow.opacity(0.24)
        }
    }

    private var shadowRadius: CGFloat {
        switch type {
        case .g_shadow_small:
            return 4
        case .g_shadow_samll_upwards:
            return 4
        case .g_shadow_medium:
            return 24
        case .g_shadow_large:
            return 32
        }
    }

    private var shadowX: CGFloat {
        switch type {
        case .g_shadow_small:
            return 0
        case .g_shadow_samll_upwards:
            return 0
        case .g_shadow_medium:
            return 0
        case .g_shadow_large:
            return 0
        }
    }

    private var shadowY: CGFloat {
        switch type {
        case .g_shadow_small:
            return 1
        case .g_shadow_samll_upwards:
            return -1
        case .g_shadow_medium:
            return 8
        case .g_shadow_large:
            return 12
        }
    }
}

extension View {
    func applyShadow(type: ShadowType) -> some View {
        return self.modifier(ShadowViewModifier(type: type))
    }
}
